<template>
	<view class="content">
		<view class="info-block">
			<template v-if="list.length>0">
				<view v-for="(item,index) in list" :key="item.id" class="info-item">
					<view style="display: flex; flex-direction: row;padding: 30rpx;">
						<image :src="item.faceUrl?item.faceUrl:'/static/mine/user_photo.png'"
							style="width: 80rpx;height: 80rpx; border-radius: 50%; background-color: #f5f5f5;margin-right: 30rpx;">
						</image>
						<view class="info-list">
							<view class="name">{{item.title}}</view>
							<view class="time">{{item.createTime}}</view>
							<view class="text">{{item.content}}</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else-if="list.length==0&&!listConf.more" style="text-align: center;">暂无数据</view>
			<view v-if="list.length>0&&!listConf.more" style="text-align: center;">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getStorage
	} from '@/util/auth';
	import {
		getIdeaList
	} from '@/api/advice.js'
	export default {
		data() {
			return {
				list: [],
				listConf: {
					page: 1,
					limit: 10,
					more: true,
				}
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getIdeaList({
					page: this.listConf.page,
					limit: this.listConf.limit,
					//userId: getStorage('login').id
				}).then(data => {
					uni.hideLoading()
					let list = data || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.listConf.more = isMore(this.listConf.page, this.listConf.limit, data.total);
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onReachBottom() {
			if (this.listConf.more) {
				this.listConf.page++;
				this.getList()
			}
		},
		onLoad() {
			this.getList(true)
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.content {
		min-height: 100vh;
		padding: 30rpx;
		background: #f5f5f5;

		.info-block {
			width: 100%;

			.info-item {
				width: 100%;
				background: #fff;
				margin-bottom: 30rpx;
				border-radius: 20rpx;
				box-shadow: 0 0 10px 0 #dedede;

				.info-list {
					width: calc(100% - 120rpx);
					display: flex;
					flex-direction: column;
					font-size: 34rpx;
					background: #fff;
					margin-bottom: 20rpx;

					.name {
						color: #027BFD;
						margin-bottom: 10rpx;
						font-weight: 600;
					}

					.text {
						font-size: 28rpx;
						font-weight: 500;
						// word-break: keep-all;
						//word-wrap: break-word;
						white-space: pre-line;
					}

					.time {
						font-size: 28rpx;
						color: #999;
						margin-bottom: 10rpx;
					}
				}
			}
		}
	}
</style>